<?php

namespace App\Http\Controllers\Common;

use App\Http\Controllers\Controller;
use App\Services\UploadService;
use Illuminate\Http\Request;

class FileController extends Controller
{
    //
    public function upload(Request $request)
    {
        if (!$request->hasFile('file')) {
            return showError('请选择文件上传');
        }
        $type = $request->input('type');
        if(empty($type)){
            return showError('请选择来源');
        }
        $file = $request->file('file');
        $uploadService = new UploadService;
        $res = $uploadService->upload($file, $type, auth('api')->user()->id ?? 0);

        if ($res['code'] == 0) {
            return showError($res["msg"]);
        }
        return showData($res['data']);

    }
}

